package com.link2room.rodimus.controller.manager;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.mns.MNSUtil;
import com.link2room.rodimus.facade.IInvoiceFacadeService;
import com.link2room.rodimus.dto.param.base.ExpressBaseDto;
import com.link2room.rodimus.dto.param.base.InvoiceBaseParamDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by VegetaKo on 2017/3/20.
 */
@Api(tags = "发票相关")
@RestController
@RequestMapping("/manager/Invoices")
public class InvoiceManagerController {
    @Resource
    private MNSUtil mnsUtil;

    @Resource
    private IInvoiceFacadeService invoiceFacadeService;

    @ApiOperation(value = "发票列表", response = ExpressBaseDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "lhotelCode", value = "酒店代码", paramType = "query", required = false),
            @ApiImplicitParam(name = "invoiceNo", value = "发票单号", paramType = "query", required = false),
            @ApiImplicitParam(name = "orderNo", value = "订单号", paramType = "query", required = false),
            @ApiImplicitParam(name = "taxpayerId", value = "税号", paramType = "query", required = false),
            @ApiImplicitParam(name = "invoiceTitle", value = "抬头", paramType = "query", required = false),
            @ApiImplicitParam(name = "terminalNo", value = "外部订单号", paramType = "query", required = false),
            @ApiImplicitParam(name = "sourceNo", value = "来源单号", paramType = "query", required = false),
            @ApiImplicitParam(name = "goodCode", value = "商品代码", paramType = "query", required = false),
            @ApiImplicitParam(name = "expressNo", value = "联房流水号", paramType = "query", required = false),
    })
    @RequestMapping(method = RequestMethod.GET)
    //TODO 无权限
    public BaseResultDto invoices(
            @RequestParam(value = "lhotelCode", required = false) String lhotelCode,
            @RequestParam(value = "invoiceNo", required = false) String invoiceNo,
            @RequestParam(value = "orderNo", required = false) String orderNo,
            @RequestParam(value = "taxpayerId", required = false) String taxpayerId,
            @RequestParam(value = "invoiceTitle", required = false) String invoiceTitle,
            @RequestParam(value = "terminalNo", required = false) String terminalNo
    ) throws Exception {
        InvoiceBaseParamDto invoiceBaseParamDto = new InvoiceBaseParamDto();
        invoiceBaseParamDto.setLhotelCode(lhotelCode);
        invoiceBaseParamDto.setInvoiceNo(invoiceNo);
        invoiceBaseParamDto.setOrderNo(orderNo);
        invoiceBaseParamDto.setTaxpayerId(taxpayerId);
        invoiceBaseParamDto.setInvoiceTitle(invoiceTitle);
        invoiceBaseParamDto.setTerminalNo(terminalNo);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setQueryResult(invoiceFacadeService.findInvoiceDetailList(invoiceBaseParamDto));
        return resDto;
    }

    @ApiOperation(value = "发票详情", response = ExpressBaseDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "invoiceNo", value = "发票单号", paramType = "query", required = false),
    })
    @RequestMapping(value = "/Invoice", method = RequestMethod.GET)
    //TODO 无权限
    public BaseResultDto invoice(
            @RequestParam(value = "invoiceNo", required = false) String invoiceNo
    ) throws Exception {
        InvoiceBaseParamDto invoiceBaseParamDto = new InvoiceBaseParamDto();
        invoiceBaseParamDto.setInvoiceNo(invoiceNo);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(invoiceFacadeService.findInvoiceDetail(invoiceBaseParamDto));
        return resDto;
    }


    @ApiOperation(value = "发票详情修改", response = ExpressBaseDto.class)
    @ApiImplicitParams(value = {
    })
    @RequestMapping(value = "/Invoice", method = RequestMethod.PUT)
    //TODO 无权限
    public BaseResultDto updateInvoice(
            @RequestBody InvoiceBaseParamDto invoiceBaseParamDto
    ) throws Exception {
        invoiceFacadeService.updateInvoiceDetail(invoiceBaseParamDto);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        return resDto;
    }

    @ApiOperation(value = "发票详情", response = ExpressBaseDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "id", paramType = "path", required = true),
    })
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public BaseResultDto invoiceById(
            @PathVariable Long id
    ) throws Exception {
        InvoiceBaseParamDto invoiceBaseParamDto = new InvoiceBaseParamDto();
        invoiceBaseParamDto.setId(id);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(invoiceFacadeService.findInvoiceDetail(invoiceBaseParamDto));
        return resDto;
    }

   /* @RequestMapping(value = "/Test",method = RequestMethod.GET)
    //TODO 无权限
    public BaseResultDto invoice() throws Exception {
        InvoiceBaseParamDto invoiceBaseParamDto=new InvoiceBaseParamDto();
        InvoiceDetailDto invoiceDetailDto=new InvoiceDetailDto();
        invoiceDetailDto.setLhotelCode("NBNY001");
        invoiceDetailDto.setLhotelGroupCode("QINGTENG");
        invoiceDetailDto.setCompanyTel("3213213123123");
        invoiceDetailDto.setOrderNo("T123123456462");
        invoiceDetailDto.setOrderName("测试订单");
        invoiceDetailDto.setOrderType(OrderTypeConstant.MALL);
        invoiceDetailDto.setPbChannel("WX");
        invoiceDetailDto.setMemberNo("TMEM00000165");
        invoiceDetailDto.setInvoiceType(1);
        invoiceDetailDto.setInvoiceTitleType(2);
        invoiceDetailDto.setInvoiceTitle("联房科技");
        invoiceDetailDto.setTaxpayerId("3123123123");
        invoiceDetailDto.setPostType(0);
        invoiceDetailDto.setEarlyPrepare(0);
        invoiceDetailDto.setWantIme(new Date());
        invoiceBaseParamDto.setInvoiceDetailDto(invoiceDetailDto);

        String remark = StringUtils.join(Arrays.asList(
                invoiceDetailDto.getInvoiceTitleTypeStr(),
                invoiceDetailDto.getInvoiceTypeStr(),
                invoiceDetailDto.getPayerStr(),
                invoiceDetailDto.getProviderStr(),
                invoiceDetailDto.getEarlyPrepareStr(),
                invoiceDetailDto.getPostTypeStr()

        ), ",");
//        mnsUtil.putMessageToQueue(RodimusMnsConstant.QUEUE_ORDER_INVOICE, JacksonUtil.beanToJson(invoiceBaseParamDto));
        BaseResultDto result = new BaseResultDto();
        result.setResultCode(0);
        result.setResultMessage(remark);
        return result;
    }*/
}
